<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<meta charset="utf-8" />
<title></title>

<link href="static/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="static/css/font-awesome.min.css" />

<link type="text/css" rel="stylesheet" href="plugins/zTree/zTreeStyle.css"/>
<link rel="stylesheet" href="static/css/ace.min.css" />
<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
<link rel="stylesheet" href="static/css/ace-skins.min.css" />


<style type="text/css">
footer{height:50px;position:fixed;bottom:0px;left:0px;width:100%;text-align: center;}
</style>

</head>
<body>
	<div id="centerOfMainFrame">
		<ul id="tree" class="tree" style="overflow:auto;"></ul>
	</div>
	<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><br/><img src="static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
	
	
	<script type="text/javascript" src="static/js/jquery-1.5.1.min.js"></script>
	<script type="text/javascript" src="plugins/zTree/jquery.ztree-2.6.min.js"></script>
	
	<script type="text/javascript">
	$(window.parent.hangge());
	var zTree;
	$(document).ready(function(){
			var setting = {
			    showLine: true,
			    checkable: true
			};
			var zn = '${zTreeNodes}';
			var zTreeNodes = eval(zn);
		    /* var zTreeNodes = [   
		                      {"id":1, "name":"test1", "nodes":[   
		                        {"id":11, "name":"test11", "nodes":[   
		                          {"id":111, "name":"test111"}   
		                        ]},   
		                        {"id":12, "name":"test12"}   
		                      ]} 
		                  ];  */
            /* var zTreeNodes = [
                          { "name":"测试模块", "id":"8", "nodes":[], "nodes":[
                          { "checked":true, "name":"测试模块子菜单1", "id":"9", "nodes":[
                          { "checked":true, "name":"测试模块子菜单1查询", "id":"9-1"},
			          	  { "checked":true, "name":"测试模块子菜单1新增", "id":"9-2"}], "nodes":[]},
			          	  
			          	  { "checked":true, "name":"测试模块子菜单2", "id":"10", "nodes":[{
			          	  "checked":true, "name":"测试模块子菜单2查询1", "id":"10-3"}, {
			          	  "checked":true, "name":"测试模块子菜单2新增", "id":"10-4"}], "nodes":[]}
			          	  ]}
			          	  ]; */
			zTree = $("#tree").zTree(setting, zTreeNodes);
		});
	</script>
	<script type="text/javascript">
		 function save(){
			var nodes = zTree.getCheckedNodes();
			var tmpNode;
			var ids = "";
			for(var i=0; i<nodes.length; i++){
				tmpNode = nodes[i];
				if(i!=nodes.length-1){
					ids += tmpNode.id+",";
				}else{
					ids += tmpNode.id;
				}
			}
			
			var roleid = "${roleid}";
			var url = "<%=basePath%>/newrole/authModuleAndOper/save.do";
			var postData = {"roleid":roleid, "moduleids":ids};
			
			$("#centerOfMainFrame").hide();
			$("#centerOfMainFrame2").show();
			$.post(url, postData, function(data){
				//if(data && data=="success"){
					top.Dialog.close();
				//}
			});
		 }
	
	</script>
	<footer>
	<div style="width: 100%;" class="center">
		<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
		<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
	</div>
	</footer>
</body>
</html>